import requestFunction from "../request";
interface ApiResponse<T = any> {
	code: number;
	data: T;
	msg?: string;
	trace_id?: string;
}
interface RequestParams {
	[key: string]: any; // 允许任意请求参数
}
interface Plan {
	pattern: number;
	property?: boolean;
	zone_pattern?: {
		zones: Array<{ zone_id: string; mode: string }>;
	};
	track_pattern?: {
		path_id: string;
	};
	self_pattern?: {
		tasks: Array<{
			task_type: string;
			path_id?: string;
			zone_id?: string;
		}>;
	};
}
interface DeviceSetRubberParams {
	device_sn: string;
	rubtype: string;
}
// 设备绑定与地图
export const getBoundVcus = (params: RequestParams) =>
	requestFunction("vcus", params, "GET");
export const getDeviceMapsApi = (params: RequestParams) =>
	requestFunction("maps", params, "GET");
export const changeMapDefault = (params: {
	map_id: string;
	device_sn: string;
}) => requestFunction("maps/default", params, "POST", { showLoading: true });
export const delDeviceMap = (params: { map_id: string; device_sn: string }) =>
	requestFunction(`maps/${params.map_id}`, params, "DELETE");
// 查询设备属性，2000hs一次
export const getDeviceShadowApi = (params: { device_sn: string }) =>
	requestFunction("vcus/shadow", params, "GET");
// 清洁计划
export const getDevicePlans = (params: RequestParams) =>
	requestFunction<Plan[]>("plans", params, "GET");
// 查询清洁进度
export const getDeviceProcessApi = (params: RequestParams) =>
	requestFunction<Plan[]>("cleans/process", params, "GET");
// 查询清洁进度提示，5000hs一次
export const getDeviceTipsApi = (params: RequestParams) =>
	requestFunction(`cleans/${params.device_sn}/tips`, params, "GET");
export const delDevicePlanApi = (params: {
	device_sn: string;
	planid: string;
	map_id: string;
}) => requestFunction("plans/delete/v2", params, "DELETE");
export const getWorkInfoApi = (params: RequestParams) =>
	requestFunction("cleans/work", params, "GET"); // 查询设备工作记录
// 设置默认清洁计划
export const setDefaultPlansApi = (params: SetDefaultPlansParams) =>
	requestFunction("plans/default", params, "POST");
// 设置避雨点
export const setRainShelterApi = (params: RequestParams) =>
	requestFunction(`vcus/${params.device_sn}/rain_shelter`, params, "PUT");
// 设备控制
export const recallDeviceApi = (params: { device_sn: string }) =>
	requestFunction("vcus/recall", params, "POST");
// 设置设备清洁强度
export const deviceSetRuberApi = (params: DeviceSetRubberParams) =>
	requestFunction("vcus/set_rubber", params, "POST");
export const deviceSwitchBrush = (
	params: { brush_type: "main" | "side"; enable: boolean },
	device_sn: string
) => requestFunction(`vcus/${device_sn}/brush`, params, "PUT");
// V2版本接口
export const createPlan = (params: PlanParams) =>
	requestFunction("plans/create/v2", params, "POST");

export const setLightUp = (params: { enable: boolean }, device_sn: string) =>
	requestFunction(`vcus/${device_sn}/light`, params, "PUT");
// 更新用户信息接口
export const updateInfo = (params: {
	device_sn: string;
}): Promise<ApiResponse> => {
	return requestFunction("staffs/update", params, "POST");
};
//取消召回 v1.9.1固件版本之后
export const cancelRecallV2Api = (params: RequestParams) =>
	requestFunction(`vcus/${params.device_sn}/cancel_recall`, params, "PUT");
// 操作清洁计划 v1.9.1固件版本之后
export const plansCtrlApi = (params: RequestParams) =>
	requestFunction("plans/ctrl/v2", params, "POST");
// 操作开启定位
export const deviceLocationApi = (params: RequestParams) =>
	requestFunction("vcus/ctrl_location", params, "POST");
// 操作重定位
export const deviceResetApi = (params: RequestParams) =>
	requestFunction("vcus/reset_location", params, "POST");
